﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace WordDowngrade
{
    [Serializable()]
    public class CategoryDict : ISerializable
    {
        private Dictionary<String, List<String>> dict;

        public CategoryDict()
        {
            dict = new Dictionary<string, List<String>>();
        }


        public CategoryDict(SerializationInfo info, StreamingContext ctxt)
        {
          dict = (Dictionary<String,List<String>>)info.GetValue("Dictionary", typeof(Dictionary<String,List<String>>));
        }



        public String[] Categories
        {
            get
            {
                Dictionary<String, List<String>>.KeyCollection keyColl =
    dict.Keys;
                String[] k = new String[dict.Keys.Count];
                int i = 0;
                foreach (string key in keyColl)
                {
                    k[i] = key;
                    i++;
                }
                return k;
            }
        }
        public int NumOfCategories
        {
            get
            { return dict.Count; }
        }
        public void addLabelToCat(String catName,String Label)
        {
            List<string> lables;
            if (dict.TryGetValue(catName, out lables))
            {
                if (lables.Contains(Label))
                {
                    return;
                }
                lables.Add(Label);
                return;
            }
            lables= new List<string>();
            lables.Add(Label);
            dict.Add(catName,lables);
        }

        public string[] getLables(String catName)
        {
            List<String> tempAns;
            if (!dict.TryGetValue(catName, out tempAns))
            {
                return null;
            }
            return tempAns.ToArray();
        }

        #region ISerializable Members

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Dictionary", dict);
        }

        #endregion
    }
}
